.TH std::reverse_iterator::operator= 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::reverse_iterator::operator= \- std::reverse_iterator::operator=

.SH Synopsis
   template< class U >                                                    \fI(until C++17)\fP
   reverse_iterator& operator=( const reverse_iterator<U>& other );
   template< class U >
   constexpr reverse_iterator& operator=( const reverse_iterator<U>&      \fI(since C++17)\fP
   other );

   The underlying iterator is assigned the value of the underlying iterator of other,
   i.e. other.base().

   This overload participates in overload resolution only if U is not the
   same type as Iter and std::convertible_to<const U&, Iter> and          \fI(since C++20)\fP
   std::assignable_from<Iter&, const U&> are modeled.

.SH Parameters

   other - iterator adaptor to assign

.SH Return value

   *this

.SH Example


// Run this code

 #include <iostream>
 #include <iterator>

 int main()
 {
     const int a1[]{0, 1, 2};
     int a2[]{0, 1, 2, 3};
     short a3[]{40, 41, 42};

     std::reverse_iterator<const int*> it1{std::crbegin(a1)};
     it1 = std::reverse_iterator<int*>{std::rbegin(a2)};   // OK
 //  it1 = std::reverse_iterator<short*>{std::rbegin(a3)}; // compilation error:
                                                           // incompatible pointer types
     std::reverse_iterator<short const*> it2{nullptr};
     it2 = std::rbegin(a3); // OK
 //  it2 = std::begin(a3);  // compilation error: no viable overloaded '='
     std::cout << *it2 << '\\n';
 }

.SH Output:

 42

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to             Behavior as published              Correct behavior
                       a std::reverse_iterator could be constructed,
   LWG 280  C++98      but not assigned, from                         also allowed
                       another std::reverse_iterator with a different assignment
                       underlying iterator type
   LWG 3435 C++20      the converting assignment operator was not     constrained
                       constrained

.SH See also

   constructor   constructs a new iterator adaptor
                 \fI(public member function)\fP
